import { Body, JsonController, Post, Get, Param, NotFoundError, Put, QueryParams } from 'routing-controllers'
import { Inject, Service } from 'typedi'
import { BasePageRequestDto, BasePageResponseDto, BaseSingleResponseDto } from '@/dtos/BaseDto';
import { SystemService } from '@/services/SystemService';
import { CreateSystemDto, SystemDto, UpdateSystemDto } from '@/dtos/SystemDto';
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';

@Service()
@JsonController('/system')
export class SystemController {

  @Inject()
  private systemService!: SystemService;

  @OpenAPI({ summary: 'Get all systems' })
  @ResponseSchema(BasePageResponseDto<SystemDto>, {
    description: 'Get all systems',
    statusCode: '200',
  })
  @Get('/')
  public async getSystems(@QueryParams() query: BasePageRequestDto): Promise<BasePageResponseDto<SystemDto>> {
    console.log('getSystems')
    console.log(this.systemService);
    return this.systemService.findAll(query);
  }

  @Get('/:id')
  public async getSystemById(@Param('id') systemId: number): Promise<BaseSingleResponseDto<SystemDto>> {
    return this.systemService.get(systemId);
  }

  @Post('/')
  public async createSystem(@Body() system: CreateSystemDto): Promise<BaseSingleResponseDto<SystemDto>> {
    console.log('createSystem')
    return this.systemService.create(system);
  }

  @Put('/')
  public async updateSystem(@Body() system: UpdateSystemDto): Promise<BaseSingleResponseDto<SystemDto>> {
    return this.systemService.update(system);
  }

  @Post('/batch-delete')
  public async batchDelete(@Body() systemIds: Array<number>): Promise<BaseSingleResponseDto<boolean>> {
    return this.systemService.batchDelete(systemIds);
  }

}
